$(function(){
	var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null;
    if (isChrome) {
        $("input[type='password']").attr("type", "text").focus(function () {
            $(this).attr("type", "password");
        });;
    } else {
        $("input[type='password']").attr("autocomplete", "off");
    }
	$('#password').val('');
	$('#loginname').val('');
	$('#login_button').on('click',function(){
		var nameData=$('#loginname').val()
		var passData=$('#password').val()
		if(nameData==''){
			layer.msg('用户名不能为空');
			return false
		}
		if(passData==''){
			layer.msg('密码不能为空');
			return false
		}
		login_submit(nameData,passData);
	})
})
login_submit=function(nameData,passData){
	/*if($('.savePass').find('input').is(':checked')){
		localStorage.loginPassword=passData;
		localStorage.loginName=nameData;
	}*/
	var data={"loginName":nameData,"password":passData};
	$.ajax({
		url:baseUrl+'/api/session/login',
		type:'POST',
		dataType:'json',
		contentType: "application/json",
		data:JSON.stringify(data),
		success:function(result){
			if(result.flag){
				layer.msg('登陆成功',1,1)
				$('#password').val('');
				$('#loginname').val('');
				window.top.location=baseUrl+"/api/main";
				if(window.top!=window){
					window.close();
				}
			}else layer.msg(result.message)
		}
	
	})
}